Release 10.1A: OpenEdge Development:
Programming Interfaces


Creating a dynamic temp-table with XML Schema

A dynamic temp-table needs its definition supplied before it can be put into a PREPARED state for reading data. Using READ-XMLSCHEMA( ) on a temp- table with no definition creates the definition from the XMl Schema. The method then places the temp-table in the PREPARED state. This code example does several things:

The read and write XML methods have many parameters. To make the code samples in this chapter more readable, each parameter is represented by a descriptively named variable. All these variable definitions are stored in an include file, shown below:

/* pi-tfx-parameterVarDefs.i */ 
/* Variables representing parameter values in the READ-XML( ),  
   READ-XMLSCHEMA( ), WRITE-XML( ), and WRITE-XMLSCHEMA( ) methods. */ 
DEFINE VARIABLE cSourceType             AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cTargetType             AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cFile                   AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cReadMode               AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cSchemaLocation         AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lOverrideDefaultMapping AS LOGICAL NO-UNDO. 
DEFINE VARIABLE cFieldTypeMapping       AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cVerifySchemaMode       AS CHARACTER NO-UNDO. 
DEFINE VARIABLE cEncoding               AS CHARACTER NO-UNDO. 
DEFINE VARIABLE lFormatted              AS LOGICAL NO-UNDO. 
DEFINE VARIABLE lWriteSchema            AS LOGICAL NO-UNDO. 
DEFINE VARIABLE lMinSchema              AS LOGICAL NO-UNDO. 
DEFINE VARIABLE lWriteBeforeImage       AS LOGICAL NO-UNDO.  

Here is the code sample:

/* pi-tfx-read-1.p */ 
/* Provides XML Schema for a new dynamic temp-table. */ 
{pi-tfx-parameterVarDefs.i} 
     
DEFINE VARIABLE returnValue AS LOGICAL NO-UNDO. 
DEFINE VARIABLE httCust AS HANDLE NO-UNDO. 
CREATE TEMP-TABLE httCust. 
     
ASSIGN 
    cSourceType = "FILE" 
    cFile = "ttCust.xsd" 
    lOverrideDefaultMapping = ? 
    cFieldTypeMapping = ? 
    cVerifySchemaMode = ?. 
DISPLAY "Is dynamic temp-table PREPARED? " httCust:PREPARED SKIP. 
DISPLAY "Reading XML Schema..." SKIP. 
     
returnValue = httCust:READ-XMLSCHEMA(cSourceType, cFile, 
                                     lOverrideDefaultMapping, 
                                     cFieldTypeMapping, cVerifySchemaMode). 
IF returnValue THEN DO: 
    DISPLAY "Is dynamic temp-table now PREPARED? " httCust:PREPARED SKIP. 
    DISPLAY "How many columns in dynamic temp-table? " 
            httCust:DEFAULT-BUFFER-HANDLE:NUM-FIELDS SKIP. 
END. 

The code displays the following:

In this next version, a non-Progress generated XML Schema file will be used to create a new dynamic temp-table. The schema is very similar to the Feedback table of the Sports2000 database. The purpose of this example is to demonstrate mapping an XML Schema field to something more useful for your Progress application.

Here is the ttFeedback.xsd file:

<?xml version="1.0" encoding="UTF-8"?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="qualified"> 
  <xsd:element name="ttFeedback"> 
    <xsd:complexType> 
      <xsd:sequence> 
        <xsd:element name="ttFeedbackRow" minOccurs="0" maxOccurs="unbounded"> 
          <xsd:complexType> 
            <xsd:sequence> 
              <xsd:element name="Contact" type="xsd:string"/> 
              <xsd:element name="Company" type="xsd:string"/> 
              <xsd:element name="EmailAddress" type="xsd:string"/> 
              <xsd:element name="Phone" type="xsd:string"/> 
              <xsd:element name="Fax" type="xsd:string"/> 
              <xsd:element name="Comments" type="xsd:string"/> 
              <xsd:element name="Department" type="xsd:string"/> 
              <xsd:element name="Rating" type="xsd:integer"/> 
            </xsd:sequence> 
          </xsd:complexType> 
        </xsd:element> 
      </xsd:sequence> 
     </xsd:complexType> 
   </xsd:element> 
</xsd:schema> 

Elements with the XMl Schema type “string” are mapped to CHARACTER fields by default.

Here is the code that maps the Comments field to a CLOB:

/* pi-tfx-read-1b.p */ 
/* Provides XML Schema for a new dynamic temp-table. */ 
{pi-tfx-parameterVarDefs.i} 
     
DEFINE VARIABLE returnValue AS LOGICAL NO-UNDO. 
DEFINE VARIABLE httFeedback AS HANDLE NO-UNDO. 
CREATE TEMP-TABLE httFeedback. 
     
ASSIGN 
    cSourceType = "FILE" 
    cFile = "ttFeedback.xsd" 
    lOverrideDefaultMapping = ? 
    cFieldTypeMapping = "Comments, CLOB" 
    cVerifySchemaMode = ?. 
DISPLAY "Is dynamic temp-table PREPARED? " httFeedback:PREPARED SKIP. 
DISPLAY "Reading XML Schema..." SKIP. 
     
returnValue = httFeedback:READ-XMLSCHEMA(cSourceType, cFile, 
                                         lOverrideDefaultMapping, 
                                         cFieldTypeMapping, cVerifySchemaMode). 
IF returnValue THEN DO: 
    DISPLAY "Is dynamic temp-table now PREPARED? " httFeedback:PREPARED SKIP. 
    DISPLAY "What is the data type of the Comments field? ” 
       httFeedback:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD("Comments"):DATA-TYPE. 
END. 

Here is the code sample output:


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095